package com.example.android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.android.R;

public class MyAdapter extends BaseAdapter {
    Context context;
    String[] nameArray;
    String[] desArray;
    String[] priceArray;

    public MyAdapter(Context context, String[] nameArray, String[] desArray, String[] priceArray) {
        this.context = context;
        this.nameArray = nameArray;
        this.desArray = desArray;
        this.priceArray = priceArray;
    }

    @Override
    public int getCount() {
        return nameArray.length;
    }

    @Override
    public Object getItem(int position) {
        return nameArray[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.goods_item_layout, null);
        }
            TextView nameTv = convertView.findViewById(R.id.name_Tv);
            TextView desTv = convertView.findViewById(R.id.des_Tv);
            TextView priceTv = convertView.findViewById(R.id.price_Tv);
            nameTv.setText(nameArray[position] + "");
            desTv.setText(desArray[position] + "");
            priceTv.setText(priceArray[position] + "");

        return convertView;
    }
}
